package com.webchat.ugc.controller.mall;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.mall.MallUserCartRequestVO;
import com.webchat.domain.vo.response.mall.MallUserCartListResponseVO;
import com.webchat.rmi.ugc.mall.MallUserCartClient;
import com.webchat.ugc.service.mall.MallUserCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class MallUserCartController implements MallUserCartClient {


    @Autowired
    private MallUserCartService mallUserCartService;

    @Override
    public APIResponseBean<Boolean> addCart(@RequestBody MallUserCartRequestVO userCartRequest) {
        boolean res = mallUserCartService.add(userCartRequest.getUserId(),
                                              userCartRequest.getSkuId(),
                                              userCartRequest.getSkuCount());
        return APIResponseBeanUtil.success(res);
    }

    @Override
    public APIResponseBean<Boolean> deleteCart(@RequestBody MallUserCartRequestVO userCartRequest) {
        boolean res = mallUserCartService.remove(userCartRequest.getUserId(),
                                                 userCartRequest.getSkuId());
        return APIResponseBeanUtil.success(res);
    }

    @Override
    public APIPageResponseBean<MallUserCartListResponseVO> page(String userId, Integer pageNo, Integer pageSize) {

        return mallUserCartService.page(userId, pageNo, pageSize);
    }

    @Override
    public APIResponseBean<Boolean> updateCount(@RequestBody MallUserCartRequestVO userCartRequest) {
        boolean res = mallUserCartService.updateCount(userCartRequest.getUserId(),
                                                      userCartRequest.getSkuId(),
                                                      userCartRequest.getSkuCount());
        return APIResponseBeanUtil.success(res);
    }
}
